﻿using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.DAL;
using AnyOffice.Components;
using log4net;
using Microsoft.ApplicationBlocks.Data;
using FunkeLab;
using System.Reflection;
using AjaxPro;
using Microsoft.VisualBasic;


namespace AnyOffice.general.mytable
{
    public partial class index : BasePage
    {

        public int ajaxInterval;      
        public string mustView;
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public index()
        {
            this.ajaxInterval = 60000;
            this.mustView = string.Empty;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string[] strArray;
            DataView view;
            System.Web.UI.Control control;
            Utility.RegisterTypeForAjax(typeof(AjaxMethods));
            ConfigManager manager = new ConfigManager();
            this.ajaxInterval = manager.AjaxInterval;
            DataTable myTable = ApplicationCache.MyTable;
            for (int i = 0; i < myTable.Rows.Count; i++)
            {
                if (Convert.ToInt32(myTable.Rows[i]["ViewType"].ToString()) == 2)
                {
                    this.mustView = this.mustView + myTable.Rows[i]["ModuleId"].ToString() + ",";
                }
            }
            UserCache cache = new UserCache();
            string mytableLeft = cache.MytableLeft;
            string mytableRight = cache.MytableRight;
            string str3 = "," + cache.FuncIdStr + ",";
            string virtualPath = string.Empty;
            if (mytableLeft != string.Empty)
            {
                strArray = mytableLeft.Split(new char[] { ',' });
                for (int j = 0; j < strArray.Length; j++)
                {
                    if (Information.IsNumeric(strArray[j]))
                    {
                        view = new DataView(myTable);
                        view.RowFilter = "ModuleId = " + strArray[j];
                        if (((view.Count > 0) && (Convert.ToInt32(view[0]["ViewType"].ToString()) != 3)) && ((Convert.ToInt32(view[0]["FuncId"].ToString()) == 0) || (str3.IndexOf("," + view[0]["FuncId"].ToString() + ",") > -1)))
                        {
                            try
                            {
                                virtualPath = view[0]["ModuleControl"].ToString();
                                control = base.LoadControl(virtualPath);
                                this.plhLeft.Controls.Add(control);
                            }
                            catch (Exception exception)
                            {
                                if (log.IsErrorEnabled)
                                {
                                    log.Error("", exception);
                                }
                            }
                        }
                    }
                }
            }
            if (mytableRight != string.Empty)
            {
                strArray = mytableRight.Split(new char[] { ',' });
                for (int k = 0; k < strArray.Length; k++)
                {
                    if (Information.IsNumeric(strArray[k]))
                    {
                        view = new DataView(myTable);
                        view.RowFilter = "ModuleId = " + strArray[k];
                        if (((view.Count > 0) && (Convert.ToInt32(view[0]["ViewType"].ToString()) != 3)) && ((Convert.ToInt32(view[0]["FuncId"].ToString()) == 0) || (str3.IndexOf("," + view[0]["FuncId"].ToString() + ",") > -1)))
                        {
                            try
                            {
                                virtualPath = view[0]["ModuleControl"].ToString();
                                control = base.LoadControl(virtualPath);
                                this.plhRight.Controls.Add(control);
                            }
                            catch (Exception exception2)
                            {
                                if (log.IsErrorEnabled)
                                {
                                    log.Error("", exception2);
                                }
                            }
                        }
                    }
                }
            }
        }

    }
}
